<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <ul class="forminfo" style="margin-top: 20px;">
    	<li><label>通知标题</label><input  class="dfinput"  type="text" name="Title" id="Title" value="" maxlength="20"/></li>
    	<li><label>通知对象</label>
    				<c:if test="${userRole <=2 }">
    	   		 	<select name="DeptCode"  id="DeptCode" class="forminfo_select">
    	   		 		<option value="00" >-- 全校 -- </option>
						<c:forEach items="${departmentInfoList}" var="departmentInfo">
							<option value="${departmentInfo.XYDM }" >${departmentInfo.XYMC }</option>
						</c:forEach>
					</select>
			    	</c:if>
			    	<c:if test="${userRole >2 }">
			   		<input value="${departmentCode }" name="DeptCode" type="hidden">${departmentName } 
			</c:if>
    </li> 
    	<li><label>通知内容</label><textarea class="long_text long_text2 " name="Content" maxlength="500"></textarea></li>

	<li><label>&nbsp;</label><input name="" type="button" onclick="submitForm();" class="btn" value="提交"/></li>
    </ul>

</body>
 	<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
     <script type="text/javascript" src="js/jquery.tips.js"></script>
     <script src="layer/layer.js"></script>
	<script type="text/javascript" >
	function submitForm() {
		if ($("input[name='Title']").val() == "") {
			showTips($("input[name='Title']"), '请填写通知标题!');
			return false;
		}
		if ($("textarea[name='Content']").val() == "") {
			showTips($("textarea[name='Content']"), '请填写通知内容!');
			return false;
		}
		    var userRole  = '${userRole }';
		    if(userRole<=2 ){
		    var ele = document.getElementById('DeptCode');
			var index = ele.selectedIndex;
			var val = ele.options[index].value;
		    }else{
		    	var val = 	$("input[name='DeptCode']").val();
		    }
						$.ajax({
							type : "POST",
							url : "news/news_save.do",
							data : {
								DeptCode :val,
								Title : $("input[name='Title']").val(),
								Content : $("textarea[name='Content']").val(),
								},
							async : true,
							dataType : "json",
							success : function(data) {
								if ("success" == data.result) {
									parent.closeAll();
								} else {
									layer.alert('发布失败!', {
										skin : 'layer-ext-moon'
									});
								}
							}
						})
		}
	function showTips(obj, tips) {
		obj.tips({
			side : 3,
			msg : tips,
			bg : '#e69138',
			time : 2
		});
	}

</script>
</html>
